home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d16 / nodee1a.arc / SOURCE.ARC / FILE.CPP < prev    next >
Text File  |  1991-09-20  |  3KB  |  150 lines

  1. /*
  2. class FileName
  3.  
  4.  
  5. deals with File names
  6.                 OtherDir(char * a) - this directory will also be searched
  7.  
  8.  BOOL   ValidFile(char * a) - finds the file in the current directory,
  9.                      or path, or default directory (if given)
  10.  
  11.  char * ShortenName(int n)
  12.                     - Returns the fully qualified file name
  13.                     limited to n characters.  Removes whole subdirectories from
  14.                     the begginning of of the full file name until the remaining
  15.                     text is shorter than n.  "..." is added to the beginning of
  16.                     the returned text.
  17.                     - Values of n less than 16 are not accepted.
  18.                     - If no file is present, returns null
  19.  
  20. */
  21.  
  22.     #include <iostream.h>
  23.     #include <fstream.h>
  24.  
  25.     #ifndef __STRING_H
  26.         #include <string.h>
  27.     #endif
  28.  
  29.     #ifndef __DIR_H
  30.         #include <dir.h>
  31.     #endif
  32.  
  33.  
  34.     #ifndef __WINDOWS_H
  35.         #include <windows.h>
  36.     #endif
  37.  
  38.  
  39.     #ifndef __NOD1_H
  40.     #include "nod1.h"
  41.     #endif
  42.  
  43.     #ifndef __FILE_H
  44.         #include "file.h"
  45.     #endif
  46.  
  47.  
  48.     BOOL FileName::ValidFile(void)
  49.     {
  50.         return bValidFile;
  51.     }
  52.     char * FileName::JustName(void)
  53.     {
  54.         return szFile;
  55.     }
  56.  
  57.     char * FileName::ShortName(int n)
  58.     {
  59.         char szTemp[MAXPATH];
  60.  
  61.         if (!bValidFile)
  62.             return NULL;
  63.         if (n < 16)
  64.             return NULL;
  65.  
  66.         if (strlen(szFile) > n)
  67.         {
  68.             strcpy(szTemp,szFullQFile);
  69.             n=n-4;
  70.  
  71.             do
  72.                 strcpy(szTemp,(char *)strchr(szTemp,'\\')+1);
  73.             while (strlen(szTemp)>n);
  74.  
  75.             strcpy(szShortFile,"...\\");
  76.             strcat(szShortFile,szTemp);
  77.  
  78.             return szShortFile;
  79.         }
  80.         else
  81.         {
  82.             return szFullQFile;
  83.         }
  84.     }
  85.  
  86.     char * FileName::LongName(void)
  87.     {
  88.         return szFullQFile;
  89.     }
  90.  
  91.  
  92. /* Evaluate the filename as follows:
  93.  
  94. - If the filename is a valid fully qualified filename,
  95.     go to that directory and set the file name.
  96. - If the command line is just a filename, search in the current directory
  97.     then the XtrDir.  If the file is valid, go to that directory and
  98.     set the file name.
  99. - If the command line is a valid directory, go to that directory and set
  100.     XtrDir to that directory.
  101.  
  102. */
  103.  
  104.     BOOL FileName::SetFile(char * szA)
  105.     {
  106.         OFSTRUCT o;
  107.         int i;
  108.  
  109.         bValidFile=FALSE;
  110.  
  111. /* if the filename contains a colon, switch to that disk before
  112. testing further */
  113.  
  114.         if (szA[1] == ':')
  115.         {
  116.             i=(int) (szA[0]-'A');
  117.  
  118.             if (i>31)
  119.                 i=i-32;
  120.  
  121.             setdisk(i);
  122.         }
  123.  
  124. /* first test the file name as is.  If the name is fully qualified,
  125. or the file is in the current or path directories this will test true.
  126. If the file is not in any of these, it is considered to not exist. */
  127.  
  128.         if (-1 != OpenFile((char * far) szA,&o,OF_READ|OF_EXIST) )
  129.         {
  130.             bValidFile=TRUE;
  131.             strcpy(szFullQFile,(char *)o.szPathName);
  132.  
  133.             if (_fstrrchr((char far *)o.szPathName,'\\') != NULL)
  134.             {
  135.                 strcpy(szFile,
  136.                     (char *) (_fstrrchr((char far *)o.szPathName,'\\')+1) );
  137.             }
  138.             else
  139.             {
  140.                 strcpy(szFile,(char *)o.szPathName);
  141.             }
  142.  
  143.         }
  144.  
  145.         return bValidFile;
  146.  
  147.     }
  148.  
  149.  
  150.